package lib.bone.nepudata.domain.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lib.bone.common.converter.JpaListLongConverter;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Author : kindear
 * @Date : 2021-12-24
 * 纵向课题关联表
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "nepu_topic")
@EntityListeners(AuditingEntityListener.class)
@ApiModel(value = "纵向课题")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class NepuTopic {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "纵向课题ID",name = "id")
    String id;

    @ApiModelProperty("周期ID")
    @Column(name = "cycle_id")
    String cycleId;

    /**
     * 课题编码
     */
    @ApiModelProperty("课题编码")
    @Column(name = "topic_code")
    String topicCode;

    /**
     * 对应课题ID 对应 nepu_topic_dict 中的 ID
     * 可以使用级联合 多对一 # 暂不使用
     */
    @ApiModelProperty(value = "对应课题类型ID",notes = "")
    @Column(name = "topic_dict_id")
    String topicDictId;

    @ApiModelProperty(value = "纵向课题名称",notes = "")
    @Column(name = "topic_name")
    String topicName;



    @ApiModelProperty("课题经费")
    @Column(name = "topic_funds",scale = 2)
    Double topicFunds;

    @ApiModelProperty("已到账经费")
    @Column(name = "reveived_funds",scale = 2)
    Double receivedFunds;

    /**
     * 纵向课题负责人姓名
     */
    @ApiModelProperty(value = "纵向课题负责人",notes = "")
    @Column(name = "leader")
    String leader;

    /**
     * 纵向课题负责人ID
     */
    @ApiModelProperty(value = "纵向课题负责人ID",notes = "")
    @Column(name = "leader_id")
    Long leaderId;

    /**
     * 纵向课题成员ID列表
     */

    @ApiModelProperty(value = "纵向课题成员ID列表",notes = "")
    @Convert(converter = JpaListLongConverter.class)
    @Column(name = "user_id_list")
    List<Long> userIdList;



//    @ApiModelProperty(value = "纵向课题执行年限",notes = "")
//    @Column(name = "year")
//    Integer year;

//    @ApiModelProperty(value = "申请状态",notes = "0：未申请；1：已申请")
//    @Column(name = "apply_status")
//    int applyStatus;
//
//    @ApiModelProperty(value = "申请人")
//    @Column(name = "applicant")
//    String applicant;

    /**
     * 是否延期
     */
    @ApiModelProperty(value = "是否是延期申报",notes = "0为正常1为延期")
    @Column(name = "is_delay")
    Integer isDelay;
//
//    /**
//     * 延期时限
//     */
//
//    @ApiModelProperty(value = "合同延期日期",notes = "合同延期日期，如2021/11/16")
//    @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
//    @Column(name = "delay_date")
//    Integer delayDate;

    /**
     * 纵向课题立项日期
     */
//    @ApiModelProperty(value = "课题立项日期",notes = "课题立项日期，如2021/11/16")
//    @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
//    @Column(name = "build_date")
//    Date buildDate;

    /**
     * 纵向课题开始日期
     */
    @ApiModelProperty(value = "课题立项日期",notes = "课题立项日期，如2021/11/16")
    @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
    @Column(name = "start_date")
    Date startDate;

    /**
     * 纵向课题完成日期
     */
    @ApiModelProperty(value = "课题结项日期",notes = "课题结项日期，如2021/11/16")
    @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
    @Column(name = "end_date")
    Date endDate;




    /**
     * 分配所得工作量
     */
    @ApiModelProperty(value = "工作量",notes = "")
    @Column(name = "workload",scale = 2)
    Double workload;


    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;
    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        NepuTopic nepuTopic = (NepuTopic) o;
        return id != null && Objects.equals(id, nepuTopic.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
